package com.oa.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtil {

	final private static String URL="jdbc:mysql://localhost:3306/oa";
	final private static String USER="root";
	final private static String PWD="123456";
	final private static String DRIVER="com.mysql.jdbc.Driver";
	
	protected Connection conn=null;
	protected PreparedStatement pst=null;
	protected ResultSet rs=null;
	
	public void open_db() throws SQLException {
		conn=DriverManager.getConnection(URL,USER,PWD);
	}
	
	public void close_db() {
		try {
			if (rs!=null) {
				rs.close();
			}
			if (pst!=null) {
				pst.close();
			}
			if (conn!=null) {
				conn.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	static {
		try {
			Class.forName(DRIVER);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
}
